Repository navigation
Conversation
db/schema/memory.ts's Drizzle column default for status contained
literal quote characters: .default("'active'"). Drizzle's SQLite
dialect binds .default() as a client-side insert parameter whenever
a column is omitted from .values() (confirmed in
node_modules/drizzle-orm/sqlite-core/dialect.js), independent of
whatever the table's raw-SQL DDL default says. store() never sets
status explicitly, so every memory was written with the 8-char
literal '\''active'\'' instead of the 6-char active.
search() and ftsSearch() already carry a widened statusFilter
(m.status = '\''active'\'' OR m.status = '\'''\'''\''active'\'''\'''\''\'') added in an
earlier unpublished fix, so legacy rows written by unpatched installs
remain searchable. That half was correct; this commit fixes the other
half so new writes stop being corrupted in the first place. Both
halves are required together.
Adds a regression suite (store.drizzle.test.ts) that asserts the raw
status column value after store(), plus end-to-end store->search()/
ftsSearch() round-trips, plus a case simulating a legacy-corrupted
row to prove the search-side widening still covers old installs.
Verified: rebuilt opencode-swarm-plugin and confirmed the fix reaches
dist/bin/swarm.js and dist/marketplace/index.js, which bundle
swarm-mail's source directly (CLI/marketplace builds mark swarm-mail
non-external specifically to avoid global-install version skew) -
patching the swarm-mail npm package alone does not affect the CLI
binary that hivemind_* tools actually invoke.
|
@srmcguirt is attempting to deploy a commit to the joelhooks' projects Team on Vercel. A member of the Team first needs to authorize it. |
📝 WalkthroughWalkthroughThe memory status default now stores ChangesMemory status handling
Estimated code review effort: 2 (Simple) | ~15 minutes Possibly related issues
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
packages/swarm-mail/src/memory/store.drizzle.test.ts (1)
364-364: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winUse the integration-test file suffix.
This suite creates and queries a libSQL database. Rename
packages/swarm-mail/src/memory/store.drizzle.test.tstopackages/swarm-mail/src/memory/store.drizzle.integration.test.ts.As per coding guidelines, “.integration.test.ts” is required for integration tests that use libSQL or the filesystem.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/swarm-mail/src/memory/store.drizzle.test.ts` at line 364, Rename the test file containing the “Memory Store (Drizzle) - Status Corruption Regression” suite to use the .drizzle.integration.test.ts suffix, preserving all test contents and behavior.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/swarm-mail/src/memory/store.drizzle.test.ts`:
- Around line 378-410: Replace the per-test client setup in the test suite’s
beforeEach with a shared createInMemorySwarmMail() instance initialized in
beforeAll and closed in afterAll. Build the Drizzle client and memory store from
that shared database, and preserve test isolation by clearing records between
tests or using unique memory IDs.
- Around line 467-486: Add a dedicated test alongside the existing legacy-status
search test that stores a memory, updates its status to the literal legacy value
'''active''', and calls ftsSearch() with a matching query. Assert that the
returned results include the legacy memory, covering the separate ftsSearch
status-filter path.
---
Nitpick comments:
In `@packages/swarm-mail/src/memory/store.drizzle.test.ts`:
- Line 364: Rename the test file containing the “Memory Store (Drizzle) - Status
Corruption Regression” suite to use the .drizzle.integration.test.ts suffix,
preserving all test contents and behavior.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 0b14e868-effc-408b-a3fb-03bef95f7599
📒 Files selected for processing (2)
packages/swarm-mail/src/db/schema/memory.tspackages/swarm-mail/src/memory/store.drizzle.test.ts
| beforeEach(async () => { | ||
| const client = createClient({ url: ":memory:" }); | ||
|
|
||
| await client.execute(` | ||
| CREATE TABLE memories ( | ||
| id TEXT PRIMARY KEY, | ||
| content TEXT NOT NULL, | ||
| metadata TEXT DEFAULT '{}', | ||
| collection TEXT DEFAULT 'default', | ||
| tags TEXT DEFAULT '[]', | ||
| created_at TEXT DEFAULT (datetime('now')), | ||
| updated_at TEXT DEFAULT (datetime('now')), | ||
| decay_factor REAL DEFAULT 1.0, | ||
| embedding F32_BLOB(1024), | ||
| valid_from TEXT, | ||
| valid_until TEXT, | ||
| superseded_by TEXT REFERENCES memories(id), | ||
| auto_tags TEXT, | ||
| keywords TEXT, | ||
| access_count TEXT DEFAULT '0', | ||
| last_accessed TEXT DEFAULT (datetime('now')), | ||
| category TEXT, | ||
| status TEXT DEFAULT 'active' | ||
| ) | ||
| `); | ||
| await client.execute(` | ||
| CREATE INDEX idx_memories_embedding | ||
| ON memories(libsql_vector_idx(embedding)) | ||
| `); | ||
|
|
||
| db = createDrizzleClient(client); | ||
| store = createMemoryStore(db); | ||
| }); |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win
Use the shared in-memory test database helper.
Line 379 creates a libSQL client directly for every test. Create the test database through createInMemorySwarmMail() in beforeAll, and close it in afterAll. Keep test records isolated by ID or clean them between tests.
As per coding guidelines, use createInMemorySwarmMail() for tests and prefer shared database instances through beforeAll and afterAll.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@packages/swarm-mail/src/memory/store.drizzle.test.ts` around lines 378 - 410,
Replace the per-test client setup in the test suite’s beforeEach with a shared
createInMemorySwarmMail() instance initialized in beforeAll and closed in
afterAll. Build the Drizzle client and memory store from that shared database,
and preserve test isolation by clearing records between tests or using unique
memory IDs.
Source: Coding guidelines
- Use shared createInMemorySwarmMailLibSQL() + toSwarmDb() harness in beforeAll/afterAll instead of a per-test raw libSQL client, per the libSQL testing pattern documented in AGENTS.md. Drops the hand-rolled CREATE TABLE / CREATE VIRTUAL TABLE DDL in favor of the real createLibSQLMemorySchema() migration path (FTS5 table + triggers included), so inserts now hit the same schema production does. - Rename store.drizzle.test.ts -> store.drizzle.integration.test.ts to match the documented suffix convention for tests touching libSQL. - Add a legacy-status ftsSearch() regression test mirroring the existing search() legacy-status case; ftsSearch() has its own status filter and was untested for the corrupted-status scenario. The raw-column assertion in the original regression test is preserved unchanged: it reads status directly via db.all(sql`SELECT status ...`), which is what actually catches the write-side bug. A store->find round-trip would not, since the widened statusFilter already masks corrupted rows on the read path.
|
Thanks for the review — all three points are valid and match the
The raw-column assertion is kept deliberately: a store→find round-trip doesn't detect this bug, because the widened Verified the regression test still catches the bug after the refactor — reverted the one-line schema default back to Note CI hasn't run yet — |
Adds a patch-level changeset for both swarm-mail and opencode-swarm-plugin. Both need bumping: opencode-swarm-plugin's CLI/marketplace build bundles swarm-mail's source directly (non-external, per build.ts comment - avoids global-install version skew), so a swarm-mail-only version bump would not by itself trigger a republish of the CLI binary that actually contains the fix. This mirrors the precedent in .changeset/fix-memory-database-path.md, an earlier memory-layer fix that bumped both packages together for the same reason.
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In @.changeset/fix-memory-status-default-quotes.md:
- Line 23: Update the fenced code block in fix-memory-status-default-quotes.md
to specify the text language by changing its opening fence to use text, while
preserving the ASCII-art content and closing fence.
- Around line 19-21: Update the changeset’s migration guidance for the
memories.status default fix: remove the claim that no migration is needed and
document the required deployment/manual database update step, or add the
corresponding ALTER/fix migration. Ensure it addresses both existing SQLite
column defaults and rows containing the corrupted '''active''' value.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 866605fc-b7ff-4b8f-ba3e-a4792b0586dd
📒 Files selected for processing (1)
.changeset/fix-memory-status-default-quotes.md
| **Migration:** none needed. The existing `statusFilter` widening (already on `main`, unchanged by this patch) keeps pre-existing corrupted rows searchable — this fix only stops *new* writes from being corrupted going forward. The widening can be dropped in a future major version once old installs have aged out. | ||
|
|
||
| **Backward compatible:** yes — no data is lost or requires backfill; previously-corrupted rows stay reachable through the existing filter, they just stop multiplying. |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
fd -t f . packages/swarm-mail | sort | while IFS= read -r file; do
if rg -q 'drizzle|migrat|CREATE TABLE|memories|status' "$file"; then
printf '\n### %s\n' "$file"
rg -n -C 4 'drizzle|migrat|CREATE TABLE|memories|status' "$file"
fi
doneRepository: joelhooks/swarm-tools
Length of output: 50379
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf 'Find relevant schema/migration/store files\n'
fd -t f 'memory.ts|migrations.ts|store.ts$|migrations' packages/swamp-mail packages/swarm-mail 2>/dev/null || true
printf '\nMemory schema around statusFilter/default\n'
sed -n '70,95p' packages/swarm-mail/src/db/schema/memory.ts 2>/dev/null || true
printf '\nMemory store read filter around statusFilter\n'
sed -n '220,240p' packages/swarm-mail/src/memory/store.ts 2>/dev/null || true
printf '\nMemory migrations definitions\n'
sed -n '1,220p' packages/swarm-mail/src/memory/migrations.ts 2>/dev/null || true
printf '\nMemory schema exports and imports\n'
rg -n "memory|create.*memory|schema_|schemaVersion|version.*memory|statusFilter" packages/swarm-mail/src -g '*.{ts,tsx,js,jsx}' | head -n 200Repository: joelhooks/swarm-tools
Length of output: 31806
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf 'Memory migrations remaining definitions\n'
sed -n '220,420p' packages/swarm-mail/src/memory/migrations.ts
printf '\nMemory migrations array exports\n'
rg -n "memoryMigrations|memorySchemaOverhaulLibSQL|memoryMigrationsLibSQL|version.*1[0-2][0-9]?|status" packages/swarm-mail/src/memory/migrations.ts packages/swarm-mail/src/memory -g '*.ts' | head -n 200
printf '\nMemory store write/insert status usages\n'
rg -n -C 4 "status|statusFilter|status.*active|new\(|insert|storeMemory|MemoryAdapter|default" packages/swarm-mail/src/memory/store.ts packages/swarm-mail/src/memory/adapter.ts packages/swarm-mail/src/memory -g '*.ts' | head -n 260Repository: joelhooks/swarm-tools
Length of output: 35382
Require migration guidance for the memories.status default fix.
default("active") does not change the default in existing SQLite memories columns or update rows where status already stores '''active'''. Either add an ALTER/fix migration or update this changeset to document the required deployment/manual update step instead of saying “Migration: none needed.”
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In @.changeset/fix-memory-status-default-quotes.md around lines 19 - 21, Update
the changeset’s migration guidance for the memories.status default fix: remove
the claim that no migration is needed and document the required
deployment/manual database update step, or add the corresponding ALTER/fix
migration. Ensure it addresses both existing SQLite column defaults and rows
containing the corrupted '''active''' value.
|
|
||
| **Backward compatible:** yes — no data is lost or requires backfill; previously-corrupted rows stay reachable through the existing filter, they just stop multiplying. | ||
|
|
||
| ``` |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Specify a language for the fenced block.
markdownlint-cli2 reports MD040 for this fence. Use text for the ASCII-art block.
Proposed fix
-```
+```text📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| ``` |
🧰 Tools
🪛 markdownlint-cli2 (0.23.2)
[warning] 23-23: Fenced code blocks should have a language specified
(MD040, fenced-code-language)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In @.changeset/fix-memory-status-default-quotes.md at line 23, Update the fenced
code block in fix-memory-status-default-quotes.md to specify the text language
by changing its opening fence to use text, while preserving the ASCII-art
content and closing fence.
Source: Linters/SAST tools
Summary
Fixes a silent data-corruption bug in
swarm-mail's memory store: every stored memory gotstatus = "'active'"(8 chars, literal embedded quotes) instead ofstatus = "active"(6 chars).search()andftsSearch()filter onstatus = 'active', so every write silently became permanently unsearchable whilegetStats()kept reporting a healthy corpus. Store succeeds, search returns empty, stats lies — indistinguishable from a legitimately empty index.Found in the wild: this silently disabled semantic memory across a full multi-agent session. Every agent's "no prior results" query looked exactly like a correctly-empty index — there was no error, no warning, nothing to notice. Only caught by manually inspecting the raw
statuscolumn againstgetStats()'s reported count.Related issue
Addresses #176 (not using a closing keyword — see why below).
#176 documents the same root-cause class of bug —
.default()receiving a SQL-literal string instead of a JS value — across eight.default()calls inmemory.ts. This PR fixes exactly one of them:status(line 86 in the issue, the one causing the reported symptom ofhivemind_findreturning 0 results). The other six the issue's own table lists as broken —metadata,collection,tags,created_at,updated_at,last_accessed— are not touched by this PR and are still broken on this branch as of this commit (access_countwas already fine per the issue). Merging this with aFixes #176keyword would auto-close an issue that isn't fully resolved.I deliberately didn't fold the other six into this PR — this fix is narrowly scoped, tested, and has a fails-without/passes-with demonstration for exactly the
statusbug. Widening it would mix an easy, well-understood, already-verified fix with five more schema changes (including two that needsqltemplate literals for thedatetime('now')defaults, a different fix shape) that haven't been through the same rigor. Suggest either: keep #176 open and re-scope its title/checklist to the remaining six, or I'm happy to open a narrowly-scoped follow-up PR for them once this one lands — your call.Bug flow
Root cause
packages/swarm-mail/src/db/schema/memory.ts:This looks like a copy-paste artifact from a raw-SQL default string, and it's easy to miss on review because the table's raw
CREATE TABLEDDL (libsql-schema.ts) already has the correctDEFAULT 'active'. Reading just the DDL, everything looks fine.But Drizzle's SQLite dialect doesn't route through the DDL default at all when a column is omitted from
.values(). It binds.default()as a client-side insert parameter instead — confirmed innode_modules/drizzle-orm/sqlite-core/dialect.js:Whatever string the JS-level
.default()was given gets bound literally as the parameter value. The correct raw-SQL DDL default is never consulted for this path — it's dead code as far as Drizzle-issued inserts are concerned.store()never setsstatusexplicitly, so everyINSERTbound the 8-character string'active'(with the quote characters as literal data) instead of the 6-characteractive.Why this survives casual review: the DDL is correct, the column name is correct, the intent (
// active, superseded) is stated right there in the comment — the only thing wrong is two stray characters buried in a.default()call, and the failure mode (silent, 100% reproducible, but invisible in stats) gives no signal to go looking for it.Why a
swarm-mail-only fix doesn't reach the shipped binaryopencode-swarm-plugin's build (packages/opencode-swarm-plugin/scripts/build.ts) has three targets:dist/index.js,dist/plugin.js) —swarm-mailis external, resolved fromnode_modulesat runtime.dist/bin/swarm.js— what thehivemind_*MCP tools actually shell out to) —swarm-mailis explicitly not external. Build script's own comment: "swarm-mail is bundled into CLI to avoid version mismatch issues with global install."dist/marketplace/index.js) — same story, bundled because that distribution ships with nonode_modules.So the CLI binary is a frozen snapshot of
swarm-mailsource at last build time. Patching only the standaloneswarm-mailpackage (e.g. a localbun add swarm-tools@patched) changes nothing the CLI executes — the fix has to land inswarm-mailsource and get rebuilt throughopencode-swarm-pluginfordist/bin/swarm.js/dist/marketplace/index.jsto pick it up. Verified directly against a from-source rebuild:grep -c 'default("active")'againstdist/bin/swarm.jsanddist/marketplace/index.jsshows the fix present in both after rebuild,dist/index.js/dist/plugin.jsshow 0 (expected — external there).This is also why the changeset (below) bumps both packages, not just
swarm-mail— aswarm-mail-only version bump wouldn't triggerchangesets/actionto republishopencode-swarm-plugin, so the CLI/marketplace tarballs on npm would stay frozen at the pre-fix source forever.The fix
(a) Schema default — the actual bug, one line:
(b) Status filter widening — already present in
main(search()andftsSearch()instore.ts, both already carry):This is a compat shim so memories already written by unpatched installs (with the corrupted
'active'literal already sitting in theirstatuscolumn) stay searchable instead of being silently orphaned by (a). This half was already correct onmainand required no change — this PR only needed (a). Both halves together: (a) stops new corruption, (b) keeps old corrupted rows reachable. (b) can be dropped in a future major version once corrupted rows have aged out / been backfilled, since it's pure legacy-compat surface.Test
Added to
store.drizzle.test.ts, a newdescribe("Memory Store (Drizzle) - Status Corruption Regression")block. The key test asserts the rawstatuscolumn value afterstore(), not just search behavior:This distinction matters: a naive
store()→find()/search()round-trip test does not catch this bug, because the filter widening in (b) already masks it — a corrupted row is still findable through the widenedOR m.status = '''active'''clause. The only way to catch the write-side bug is to inspect the column directly. That's exactly why it survived undetected — every "does search still work" sanity check passes even with the schema bug present.Plus:
store()→search()round tripstore()→ftsSearch()round tripsearch()still finds a row with the legacy-corrupted status value (protects against (b) being narrowed again later)Demonstrated fails-without-fix / passes-with-fix
Reverted the schema line locally, reran:
Restored the fix, reran:
Maintainers can rerun this yourselves: revert the one-line diff in
memory.tsabove, run the targeted test, confirm theExpected: "active", Received: "'active'"failure, then restore it and confirm green.Verification
One flaky, unrelated failure (
session-handoff.test.ts, an ordering assertion —Expected: 8, Received: 9) appeared on the first full-suite run and was gone on rerun. Reproduced independently against this branch's unmodified tip by stashing this PR's changes and rerunning in isolation — same intermittent failure, confirming it's a pre-existing timing flake in that test's own setup, unrelated to this change. Flagging so it isn't mistaken for something this PR introduced.For the maintainer — release housekeeping
A few things that make this land cleanly with minimal back-and-forth:
Changeset — added
.changeset/fix-memory-status-default-quotes.md, patch-level for bothopencode-swarm-pluginandswarm-mail, following the "lore" convention documented inAGENTS.md(epigraph, before/after, ASCII art). Bumps both packages for the vendoring reason described above — matches the precedent set by.changeset/fix-memory-database-path.md, an earlier memory-layer fix that did the same for the same reason.Data migration — not needed. The existing
statusFilterwidening insearch()/ftsSearch()(unchanged by this PR, already onmain) keeps rows with the corrupted'active'literal permanently searchable. Installs running the buggy version don't need any backfill; they just stop accumulating new corruption once this ships. A normalization migration to actually clean up the corrupted rows would be a nicer end state but is out of scope here — flagging it as a possible future cleanup, not blocking.Vouch — already satisfied, no action needed on your end.
srmcguirtis already in.github/VOUCHED.td, which is presumably why this PR wasn't auto-closed byvouch-check-pr.yml.CI status — as of this update,
Vercelshowsfailure, but that's an expected team-authorization gate on preview deploys for external contributors (unrelated to this change — it needs a team member to click "authorize" in the Vercel dashboard, not a code fix).CodeRabbitand bothSocket Securitychecks pass.CIandEval Gatehaven't run at all yet — no workflow runs exist for this commit — because GitHub requires a maintainer to approve workflow runs for a first-time contributor. Whenever you get a moment: "Approve and run workflows" on this PR.Issue linking — see the "Related issue" section above; used
Addresses #176rather than a closing keyword since #176 documents more than this PR fixes.Test summary
swarm-mailsuitetsc --noEmit)Expected: "active", Received: "'active'")swarm-mail,opencode-swarm-plugin)Credits
Bug found the hard way, in production, by a multi-agent swarm quietly losing all its memory for an entire session while reporting itself perfectly healthy. Root-caused down to the Drizzle dialect source. No AI agents were harmed in the making of this fix, though several were mildly confused about why nothing they remembered was coming back.
Summary by CodeRabbit